/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.futco.sysconthos.Modelo.Procesos.Daos;

import org.futco.sysconthos.Modelo.Admisiones.Daos.IDAO;
import org.futco.sysconthos.Modelo.Admisiones.Daos.Model;
import org.futco.sysconthos.Modelo.Proceso.Horario;
import com.mysql.jdbc.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;

/**
 *
 * @author Server
 */
public class HorarioDAO implements IDAO <Horario>{
     private Model model;
 private PreparedStatement psInsert;

  public HorarioDAO() throws SQLException {
        model = Model.getInstance();
    }
    public void insert(Horario t) throws SQLException {
         if (psInsert == null) {
            String sqlInsert = "INSERT INTO horario (codigo, nombre, horaInicio, horaFin) VALUES (?,?,?,?)";
            psInsert = (PreparedStatement) model.getCon().prepareStatement(sqlInsert);

        psInsert.setString(1, t.getCodigo());
        psInsert.setString(2, t.getNombre());
        psInsert.setObject(3, t.getHoraInicio());
        psInsert.setObject(4, t.getHoraFin());
        psInsert.executeUpdate();
        }
    }

    public void delete(Horario t) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public List<Horario> getAll() throws SQLException {
          Horario pro=null;
      PreparedStatement ps=null;
      ResultSet rs=null;
      List lista= new LinkedList();

      try{
          String sqlInsert = "Select * from horario";
          ps=(PreparedStatement) model.getCon().prepareStatement(sqlInsert);
          rs=ps.executeQuery();
          while(rs.next()){
              pro=this.loadHorario(rs);
              lista.add(pro);
          }

      }finally{
          if(rs!=null){
              rs.close();
          }
          if(ps!=null){
              ps.close();
          }
      }
      return lista;
    }

    public List<Horario> getAllBy(String t, String n) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public Horario find(Integer id) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public void update(String codigo, Horario t) throws SQLException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    private Horario loadHorario(ResultSet rs) throws SQLException {

        Horario h=new Horario();
       h.setCodigo(rs.getString("codigo"));
       h.setNombre(rs.getString("nombre"));

      return h;
    }

}
